{extend name="layout/layout" /}

{block name="pagecss"}
{/block}

{block name="content"}
<div class="row js-check-wrap">
    <div class="col-lg-12">
        <div class="box box-success">
            <div class="box-header with-border">
                <h3 class="box-title">用户获取积分的规则</h3>
            </div>
            <div class="box-body">
                <form id="modal_new_role" class="form-horizontal form" method="post" enctype="multipart/form-data">
                    <div class="form-body">
                        <div class="row">
                            <div class="form-group">
                                <label class="control-label col-md-3">
                                    <span class="required" aria-required="true">*</span>
                                    账户充值积分：
                                </label>
                                <div class="  form-inline">
                                    <span>&nbsp;每充值&nbsp;</span>
                                    <input type="text" class="form-control" id="rechargeNum" name="rechargeNum" value="{$info.rechargeNum ? $info.rechargeNum / 100 : ''}" maxlength="12">
                                    <span>&nbsp;元&nbsp;</span>
                                    &nbsp;&nbsp;&nbsp;
                                    <span>&nbsp;送积分&nbsp;</span>
                                    <input type="text" class="form-control" id="integralNum" name="integralNum" value="{$info.integralNum ? : '0'}" maxlength="12">（填0表示不送积分）
                                </div>
                            </div>
                        </div>

                        <input type="hidden" name="id" value="{$info.id ? : ''}">
                        <hr />

                        <div class="form-actions">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group" style="margin-left: 250px">
                                        <label class="col-md-3 control-label"></label>
                                        <div class="col-md-9" >
                                            <button type="button" id="save-btn" class="btn btn-primary">
                                                保存 <i class="fa fa-floppy-o"></i>
                                            </button>
                                            <!--<button type="button" id="btn_cancle" class="btn btn-default" onclick="history.go(-1);">
                                                返回 <i class="fa fa-mail-forward"></i>
                                            </button>-->
                                            <span class="help-block "></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<input type="hidden" class="save-url" value="{:url('admin/integralRule/index')}" >
{/block}

{block name="pagescript"}
<script>
    $("#save-btn").on('click', function () {
        var rechargeNum = $('#rechargeNum').val();
        var integralNum = $('#integralNum').val();

        if(rechargeNum.trim() == ''){
            layer.msg('充值金额不能为空！');
            return false;
        }
        var price_reg = /^(([0-9]+[\.]?[0-9]+)|[1-9])$/;
        if(!price_reg.test(rechargeNum)){
            layer.msg('充值金额格式不正确！');
            return false;
        }
        var price_reg2 = /^\d+(\.\d{1,2})?$/;
        if(!price_reg2.test(rechargeNum)){
            layer.msg('充值金额小数点后只有两位！');
            return false;
        }

        var num_reg = /^\+?[0-9][0-9]*$/;
        if(!num_reg.test(integralNum) || integralNum.length > 12){
            layer.msg('积分数量需为12位以内的正整数！');
            return false;
        }

        var url = $('.save-url').val();
        var data = $('#modal_new_role').serialize();
        $.ajax({
            url: url,
            type: 'POST',
            data: data,
            cache: false,
            dataType : 'json',
            success: function (data) {
                console.log(data);
                layer.msg(data.msg);
            }
        });
        return false;
    });
</script>
{/block}